package cn.copera.dyy.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.copera.dyy.common.utils.StringUtils;
import cn.copera.dyy.common.web.BaseController;
import cn.copera.dyy.entity.PointPraiseSet;
import cn.copera.dyy.entity.Shop;
import cn.copera.dyy.entity.ShopImage;
import cn.copera.dyy.service.PointPraiseSetService;
import cn.copera.dyy.service.ShopService;
import cn.copera.dyy.service.TrackService;

/**
 * 手机端Controller
 * 
 * 
 */
@Controller
@RequestMapping(value = "${adminPath}/login")
public class LoginController extends BaseController {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	ShopService shopService;
	@Autowired
	TrackService trackService;    
	@Autowired
	PointPraiseSetService pointPraiseSetService;
	
	@RequestMapping(value = "/shoplist", method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> deptlist() {
		Map<String, Object> map = new HashMap<String, Object>();
		List<Shop> list =shopService.findAll();
		
		
		map.put("list", list);
		return map;
	}
	@RequestMapping(value="",method = RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> login(@RequestParam(required = false) String account,String password){
		
		Map<String, Object> map = new HashMap<String,Object>();
		
		String message = shopService.checkLogin(account, password);
		if ("登录成功".equals(message)) {
			String shopId = "";
			Shop shop = shopService.findShop(account);
			//店铺二级用户登录
			if (shop.getParent() != null) {
				account = shop.getParent().getLoginName();
				shopId = shop.getParent().getId();
				map = shopService.count(account);
				Shop sh = shop.getParent();
				sh.setId(shop.getId());
				sh.setLoginName(shop.getLoginName());
				sh.setPhone(shop.getPhone());
				map.put("shop",sh);
			}else {
				map = shopService.count(account);
				map.put("shop",shop);
				shopId = shop.getId();
			}
			map.put("shopId", shopId);
			PointPraiseSet set = pointPraiseSetService.findPointPraiseSeByShop(shopId,"点赞");
			if(set!=null){
				map.put("pointPraiseSet", set);//获取店面点赞设置
			}else{
				map.put("pointPraiseSet", new PointPraiseSet());
			}
			set = pointPraiseSetService.findPointPraiseSeByShop(shopId,"分享");
			if(set!=null){
				map.put("shareSet", set);//获取店面点赞设置
			}else{
				map.put("shareSet", new PointPraiseSet());
			}
			ShopImage shopImage = shopService.findShopImg(shopId);
			if(shopImage!=null){
				map.put("shopImage", "1");
			}else{
				map.put("shopImage", "2");
			}

			
		}
		map.put("message", message);
		map.put("message", message);
		return map;
	}
}
